package p3.enunciado;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

import p3.IHandler;

public class CloseConnectionHandler implements IHandler {

    protected Socket connection;

    public CloseConnectionHandler(Socket s) {
        connection = s;
    }

    @Override
    public void doService() {
        if (connection == null) {
            System.out.println("CloseConnectionHandler: Error. Socket cliente == null");
            return;
        }
        try {
            // Stream para escribir en el socket.
            PrintWriter streamWriter = new PrintWriter(connection.getOutputStream());
            streamWriter.println(Servidor.CloseConnection);
            streamWriter.flush();

        } catch (IOException ioe) {
            System.out.println("CloseConnectionHandler: " + ioe.getMessage());
        }

    }

    @Override
    public void setHandlerSocket(Socket s) throws IOException {
        connection = s;
    }
}
